<?php
namespace jy_liangoods;
defined('BY_JYA') or exit('error');
/*
*/
class commission extends \plugin{
	/*
		
	*/
	/*
		订单结算
	*/
	public function pay_clearing($clearing_id,$pay_type){
		$clearing=$this->get('balance',array('id'=>$clearing_id,'uniacid'=>$_SESSION['uniacid']));
		$clearing['mid']=pdo_getcolumn('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$clearing['merchid']),'mid');
		if(!$clearing || $clearing['status']!=1){
			exi('结算单不存在或者不符合打款条件，打款失败！','error');
		}
		$pay_type=$pay_type?:$clearing['pay_type'];
		$pay_types=array_keys($this->pay_types);
		if(!$pay_type || !in_array($pay_type,$pay_types)){
			exi('未设置打款方式或者打款方式不合法，打款失败！','error');
		}
		$func_name='pay_balance_by_'.$pay_type;
		$trade_no=$this->$func_name($clearing['mid'],$clearing['final_money'],$clearing['balancesn'],'商户提现');
		$update=array(
			'status'=>2,
			'pay_type'=>$pay_type,
			'pay_trade_no'=>$trade_no,
			'pay_time'=>TIMESTAMP,
		);
		$this->update('balance',$update,array('id'=>$clearing['id']));
		$this->model('notice')->notice_fenxiao_dakuan($clearing['mid'],$clearing['final_money']);
		return true;
	}
	/*
		打款到余额
	*/
	protected function pay_balance_by_credit($mid,$money,$balancesn){
		return cfc('core')->member_credit($mid,'credit2',$money,true,$this->plugin_name,'商户提现打款');
	}
	/*
		打款到微信零钱
	*/
	protected function pay_balance_by_wechat($mid,$money,$balancesn){
		$params=array(
			'openid'=>$mid,
			'mch_billno'=>$balancesn,
			'money'=>$money,
			'remark'=>'商户提现打款',
		);
		$res=cfc('wechat_pay')->mch_pay($params);
		return $res['payment_no'];
	}
	/*
		打款到支付宝
	*/
	protected function pay_balance_by_alipay($mid,$money,$balancesn){
		return 'pay_trade_no';
		exi('暂不支持打款到支付宝！','error');
	}
	/*
		打款到银行账户
	*/
	protected function pay_balance_by_union($mid,$money,$balancesn){
		return 'pay_trade_no';
		exi('暂不支持打款到银行账户！','error');
	}

}